package com.example.demo;


import com.agentsflex.core.llm.Llm;
import com.agentsflex.core.message.HumanMessage;
import com.agentsflex.core.prompt.HistoriesPrompt;
import com.agentsflex.llm.moonshot.MoonshotLlm;
import com.agentsflex.llm.moonshot.MoonshotLlmConfig;
import com.agentsflex.llm.qwen.QwenLlm;
import com.agentsflex.llm.qwen.QwenLlmConfig;
import com.agentsflex.llm.spark.SparkLlm;
import com.agentsflex.llm.spark.SparkLlmConfig;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Scanner;

@SpringBootTest
public class AgentsFlexQwenLlm {
    String commonQuest1 ="";
    // 通义千问
   // @Test
    public void TestAgentsFlexQwen(){
        QwenLlmConfig config = new QwenLlmConfig();
        config.setApiKey("sk-ffd6b38b8ead44578fec85bfe2c5a0ad");

        Llm llm = new QwenLlm(config);
        System.out.println("***************");
        System.out.println("***************");
        System.out.println("***************");
        String response = llm.chat("你是谁?");
        System.out.println(response);
        System.out.println(commonQuest1);
        System.out.println(llm.chat(commonQuest1));
    }

    // Kimi
    //@Test
    public void TestAgentsFlexKimi(){
        MoonshotLlmConfig config = new MoonshotLlmConfig();
        config.setApiKey("sk-lYnSOuOMMn4xRq34rXzXzR7ZOUL2OlMSVpkGFnMJqem0SzXv");

        Llm llm = new MoonshotLlm(config);
        System.out.println("***************");
        System.out.println("***************");
        System.out.println("***************");
        String response = llm.chat("你是谁?");
        System.out.println(response);
        System.out.println(commonQuest1);
        System.out.println(llm.chat(commonQuest1));
    }

    // 科大讯飞星火大模型
    //@Test
    public void TestAgentsFlexSpark(){
        SparkLlmConfig config = new SparkLlmConfig();
        config.setAppId("6f3cb10e");
        config.setApiKey("e2d3712f2d6c6d6a4a262219a35c56ea");
        config.setApiSecret("MzczYTEwNjM5NGU2NTQ5YzVlYTA5MWFm");

        Llm llm = new SparkLlm(config);
        System.out.println("***************");
        System.out.println("***************");
        System.out.println("***************");
        String response = llm.chat("你是谁");
        System.out.println(response);
        System.out.println(commonQuest1);
        System.out.println(llm.chat(commonQuest1));
    }

    @Test
    public void TestAgentsFlex(){
        this.commonQuest1 = "哄女朋友开心的最好方法是什么？200个字以内。";
        TestAgentsFlexSpark();
        TestAgentsFlexKimi();
        TestAgentsFlexQwen();
    }

    // 连续对话
    @Test
    public void TestHistoriesPrompt(){
        // 自定义虚拟选型 新增一条：-Deditable.java.test.console=true
        SparkLlmConfig config = new SparkLlmConfig();
        config.setAppId("6f3cb10e");
        config.setApiKey("e2d3712f2d6c6d6a4a262219a35c56ea");
        config.setApiSecret("MzczYTEwNjM5NGU2NTQ5YzVlYTA5MWFm");

        Llm llm = new SparkLlm(config);

        HistoriesPrompt prompt = new HistoriesPrompt();

        System.out.println("您想问什么？");
        Scanner scanner = new Scanner(System.in);
        String userInput = scanner.nextLine();

        while (userInput != null) {

            prompt.addMessage(new HumanMessage(userInput));

            llm.chatStream(prompt, (context, response) -> {
                System.out.println(">>>> " + response.getMessage().getContent());
            });

            userInput = scanner.nextLine();
        }
    }
}
